<template>
  <div class="app">
    <div class="layout">
      <div>
        <div class="My_title">
          <img
            class="My_bg"
            src="http://liufusong.top:8080/img/profile/bg.png"
            alt=""
          />
          <div class="My_info">
            <div class="My_myIcon">
              <img
                class="My_avatar"
                src="http://liufusong.top:8080/img/profile/avatar.png"
                alt="icon"
              />
            </div>
            <div class="My_user">
              <div class="My_edit" v-if="!flag">
                <div class="My_name">游客</div>
                <van-button round type="primary" class="btn" to="/login"
                  >去登录</van-button
                >
              </div>
              <div class="My_edit" v-else>
                <div class="My_name">888</div>
                <van-button round type="primary" class="btn" to="/my"
                @click="Tuichu"
                  >退出</van-button
                >
                <div class="edit">编辑个人资料 ></div>
              </div>
            </div>
          </div>
        </div>

        <div class="am-grid">
          <van-grid :column-num="3">
            <van-grid-item icon="star-o" text="我的收藏" @click="goCollect" />
            <van-grid-item icon="wap-home-o" text="我的出租" @click="gochuzu" />
            <van-grid-item icon="clock-o" text="看房记录" />
            <van-grid-item icon="idcard" text="成为房主" />
            <van-grid-item icon="contact" text="个人资料" />
            <van-grid-item icon="service-o" text="联系我们" />
          </van-grid>
        </div>
        <div class="My_ad">
          <img src="http://liufusong.top:8080/img/profile/join.png" alt="" />
        </div>
      </div>
      <div><router-view> </router-view></div>
    </div>
  </div>
</template>

<script>
import { delToken, getToken } from '@/utils/storage'
import { Dialog } from 'vant'
// import { GetInfo } from '../api/login'
export default {
  name: 'My-vue',
  data () {
    return {
      // flag: getToken()
    }
  },
  methods: {
    goCollect () {
      this.$router.push('/shoucang')
    },
    gochuzu () {
      this.$router.push('/chuzu')
    },
    Tuichu () {
      delToken()
      Dialog.alert({
        message: '您确定要退出账户嘛'
      }).then(() => {
        // on close
        this.flag = false
        this.$router.go(0)
      })
    }
  },
  computed: {
    flag () {
      if (getToken()) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>

<style leng="less">
* {
  box-sizing: border-box;
  font-family: "Microsoft YaHei";
}
.app {
  background-color: #fff;
  font-family: "Microsoft YaHei";
}
.My_title {
  min-height: 300px;
  position: relative;
}
.My_bg {
  width: 100%;
}
.My_info {
  position: absolute;
  background: #fff;
  width: 85%;
  height: 55%;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px 3px #ddd;
  margin: 50px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 13px;
}
.My_myIcon {
  position: relative;
  transform: translateY(-50%);
  border-radius: 50%;
  width: 70px;
  height: 70px;
  border: 5px solid #f5f5f5;
  display: inline-block;
  box-shadow: 0 2px 2px #bdbdbd;
}
.My_avatar {
  width: 100%;
  border-radius: 50%;
}
.My_user {
  padding-top: 15px;
}
.My_name {
  margin-top: -50px;
  margin-bottom: 10px;
}
.My_edit {
  color: #999;
  font-size: 12px;
  margin-top: 20px;
}
.btn {
  display: inline-block;
  font-size: 13px;
  height: 30px !important;
  line-height: 30px;
  padding: 0 15px;
}
.am-grid {
  margin-top: 5px;
  height: 190px;
}
.am-grid div {
  height: 95px;
}
.My_ad {
  margin-top: 5px;
  text-align: center;
}
.My_ad img {
  width: 92%;
}
.edit {
  margin-top: 8px;
}
</style>
